#include <stdio.h>
#include <errno.h>  //errno
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
	if (3 != argc)
	{
		printf("参数有问题...\n");
		exit(EXIT_FAILURE);
	}
	FILE *src = fopen(argv[1], "r");
	if (NULL == src)
	{
		printf("打开%s失败-->%s\n", argv[1], strerror(errno));
		exit(EXIT_FAILURE);
	}
	FILE *dest = fopen(argv[2], "w");
	if (NULL == dest)
	{
		printf("打开%s失败-->%s\n", argv[2], strerror(errno));
		close(src);
		exit(EXIT_FAILURE);
	}

	char caBuf[4096] = {'\0'};
	while (1)
	{
		memset(caBuf, 0, 4096);
		if (NULL == fgets(caBuf, 4096, src))
		{
			break;
		}
		fputs(caBuf, dest);
	}

	fclose(src);
	fclose(dest);

	return 0;
}
